package com.jixiantubu.wode;

import image.SmartImageView;
import java.util.ArrayList;
import java.util.List;
import com.example.jixiantubu.R;
import com.jixiantubu.adapter.Wo_guanzhugerenAdapter;
import com.jixiantubu.bean.UserBean;
import com.jixiantubu.bean.Wo_Data;
import com.jixiantubu.util.MyApplication;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.TextView;

public class GuanzhuderenActivity extends Activity {

	UserBean userbean;
	List<Wo_Data> list = new ArrayList<Wo_Data>();
	Wo_guanzhugerenAdapter adapter;
	ListView listview1;
	Intent intent;
	SmartImageView wo_imagebt1;
	TextView textView1, quxiaoguanzhu;
	HttpUtils httpUtils = new HttpUtils();
	String username;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Window window = this.getWindow();
		window.requestFeature(window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_guanzhuderen);
		initView();
		initData();
	}

	private void initView() {
		Intent itent = getIntent();
		userbean=(UserBean) itent.getSerializableExtra("user_id");
		username=itent.getStringExtra("username");
		listview1 = (ListView) findViewById(R.id.wo_guanzhugeren);
		wo_imagebt1 = (SmartImageView) findViewById(R.id.wo_imagebt1);
		textView1 = (TextView) findViewById(R.id.textView1);
		quxiaoguanzhu = (TextView) findViewById(R.id.quxiaoguanzhu);
		if (username.equals(MyApplication.username)) {
			quxiaoguanzhu.setText("取消关注");
			quxiaoguanzhu.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View view) {
					RequestParams params =new RequestParams();
					params.addBodyParameter("key", "5");
					params.addQueryStringParameter("username", MyApplication.username);
					params.addQueryStringParameter("focuse",username);
					Log.e("倍关注的人", userbean.getUser_name());
					String url = "http://" + MyApplication.getIP()
				+ ":8080/Jinnang/WoGuanzhu";
					httpUtils.send(HttpMethod.POST, url,params,
							new RequestCallBack<String>() {

								@Override
								public void onFailure(HttpException arg0,
										String arg1) {

								}

								@Override
								public void onSuccess(ResponseInfo<String> arg0) {

									quxiaoguanzhu.setText("关注");
								}
							});

				}
			});
		}else{
			quxiaoguanzhu.setVisibility(View.GONE);
		}
		
		

	}

	private void initData() {
		Wo_Data d1 = new Wo_Data(R.drawable.wodetiezi, "他的帖子");
		Wo_Data d2 = new Wo_Data(R.drawable.wodeshoucang, "他的收藏");
		Wo_Data d3 = new Wo_Data(R.drawable.wodeguanzhu, "他的关注");
		Wo_Data d4 = new Wo_Data(R.drawable.wodejieban, "他的结伴");

		list.add(d1);
		list.add(d2);
		list.add(d3);
		list.add(d4);

		adapter = new Wo_guanzhugerenAdapter(list, GuanzhuderenActivity.this);
		listview1.setAdapter(adapter);
		listview1.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				
				switch (arg2) {
				case 0:
					intent=new Intent(GuanzhuderenActivity.this,Wo_tieziActivity.class);
					intent.putExtra("username",username);
					startActivity(intent);
					break;
				case 1:
					intent=new Intent(GuanzhuderenActivity.this,Wo_shoucangActivity.class);
					intent.putExtra("username",username);
					startActivity(intent);
					break;
				case 2:
					intent=new Intent(GuanzhuderenActivity.this,Wo_guanzhuActivity.class);
					intent.putExtra("username", username);
					startActivity(intent);
					break;
				case 3:
					intent=new Intent(GuanzhuderenActivity.this,Wo_jiebanActivity.class);
					intent.putExtra("username", username);
					startActivity(intent);
					break;
				default:
					break;
				}

			}
		});

		textView1.setText(userbean.getUser_nickname());
		String url = "http://" + MyApplication.getIP()
			+ ":8080/Jinnang/img/"
				+ userbean.getUser_imgPath();
		wo_imagebt1.setstyle("circle");
		wo_imagebt1.setImageUrl(url);

	}
}
